package com.rchat.pocmini.activity.groupsselect;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.rchat.pocmini.R;
import com.rchat.pocmini.activity.fragment.groups.GroupsPresenterImpl;
import com.rchat.pocmini.activity.groupsselect.view.GroupSelectBean;
import com.rchat.pocmini.activity.groupsselect.view.GroupsSelectorListView;
import com.rchat.pocmini.activity.main.MainActivity;
import com.rchat.pocmini.common.mvp.BaseMvpActivity;


import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by itsdf07 on 2017/8/31.
 */

public class GroupsSelectorActivity extends BaseMvpActivity<GroupsSelectorPresenterImpl, GroupsSelectorModelImpl> implements
        GroupsSelectorContract.View {
    @BindView(R.id.lv_groupsSelector)
    GroupsSelectorListView mLvGroupsSelector;
    @BindView(R.id.btn_cancle)
    TextView mBtnCancle;
    @BindView(R.id.btn_confirm)
    TextView mBtnConfirm;
    @BindView(R.id.btn_back)
    View mBtnBack;

    @Override
    public void initPresenter() {
        mPresenter.setVM(this, mModel);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_groupsselector;
    }

    @Override
    public void initView() {
    }

    @Override
    public void doAfterInitView() {

    }

    @OnClick({R.id.btn_cancle, R.id.btn_confirm, R.id.btn_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancle:
                mPresenter.notifyUpdateGroups();
                break;
            case R.id.btn_confirm:
                mPresenter.checkKeepGroups(mLvGroupsSelector.getSelectData());
                break;
            case R.id.btn_back:
                mPresenter.notifyUpdateGroups();
                break;
        }
    }

    @Override
    public void updateList(ArrayList<GroupSelectBean> bean) {
        mLvGroupsSelector.setData(bean);
    }

    @Override
    public void onBackToMain() {
        //执行到MainActivity的onNewIntent生命周期里
        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra(GroupsPresenterImpl.KEY_GROUPID, "");
        startActivity(intent);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mPresenter.notifyUpdateGroups();
    }
}
